#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

string largestNumber(vector<int>& nums) {
    priority_queue<string> heap;
    for (auto& x : nums)
        heap.push(to_string(x));

    string ret;
    while (heap.size() > 1) {
        string a = heap.top();
        heap.pop();
        string b = heap.top();
        heap.pop();
        if (a + b < b + a)
            ret += b, heap.push(a);
        else
            ret += a, heap.push(b);
    }
    if (ret[0] == '0')
        return "0";
    else {
        ret += heap.top();
        heap.pop();

        return ret;
    }
}

int main() {
    vector<int> num{ 74,21,33,51,77,51,90,60,5,56 };
    cout << largestNumber(num);
}